package test3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class BuildServerSocket {

    public static void main(String[] args) {
        User user = new User();
        PrintWriter out = null;
        Socket socket =null;
        ObjectInputStream ois = null;
        BufferedReader br = null;
        try {
            ServerSocket serverSocket = new ServerSocket(12345);
             socket = serverSocket.accept();
            ois = new ObjectInputStream(socket.getInputStream());

            out = new PrintWriter(socket.getOutputStream());
             user = (User) ois.readObject();

             if(user.getName().equals("bjsxt")&& user.getPasword().equals("bjsxt")){
                 out.println("登录成功！");
                 out.flush();
             }
             else {
                 out.println("登录失败！");
                 out.flush();
             }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
                ois.close();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
